﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StatePattern
{
    class Context
    {
        public sealed static State STATE1 = new ConcreteState1();
        public sealed static State STATE2 = new ConcreteState2();

        private State _state;
        /// <summary>
        /// 获取或设置当前的状态
        /// </summary>
        public State State
        {
            get
            {
                return _state;
            }
            set
            {
                //设置当前状态
                _state = value;
                //切换状态
                this.State.Context = this;
            }
        }
        /// <summary>
        /// 行为委托
        /// </summary>
        public void Handle1()
        {
            this._state.handle1();
        }

        public void Handle2()
        {
            this._state.handle2();
        }

        
    }
}
